package com.example.administrator.myrecycleview_420lx.model;


import com.example.administrator.myrecycleview_420lx.iface.RegisterListener;
import com.example.administrator.myrecycleview_420lx.service.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Yrx on 2017/5/25.
 */

public class RegisterModel{
    Retrofit retrofit;
    private static String BASEURL="http://amicool.neusoft.edu.cn/";

    public RegisterModel() {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void register(String userName, String passWord, String tel, final RegisterListener listener){
        RegisterService service =retrofit.create(RegisterService.class);
        Call<String> call=service.getRegister(userName,passWord,tel);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                RegisterListener listener = null;
                if(response.body()!=null && response.isSuccessful()){

                    listener.onResponse(response.body());

                }
                else{

                    listener.onFail("onResponse fail");//使用了java的回调机制
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}